package cn.wawi.dao.sys;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import cn.wawi.common.annotation.MybatisRepository;
import cn.wawi.dao.BaseDao;
import cn.wawi.entity.sys.Role;

@MybatisRepository
public interface RoleDao<T extends Role> extends BaseDao<T> {

	/**
	 * 获取用户所拥有的角色
	 * @param userId 用户id
	 * @return 角色列表
	 */
	@Select("SELECT  r.*  FROM sys_role r LEFT JOIN sys_user_role ur ON  r.id=ur.role_id WHERE ur.user_id=#{userId}")
	List<Role> getUserRole(int userId);

	@Insert("insert into sys_user_role values(#{userId},#{roleId})")
	void saveUserRole(@Param("userId")int userId,@Param("roleId") int roleId);
	
	@Delete("delete from sys_user_role where user_id=#{userId}")
	int deleteUserRole(@Param("userId")int userId);
}

